package com.hui.xiao.xiaohui.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.Toast;

import com.hui.xiao.xiaohui.R;

/**
 * Created by Administrator on 2016/5/22.
 */
public class PopupMenuTest extends Activity {
    PopupMenu popupMenu = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popup_menu);
    }

    public void popup(View view) {
        popupMenu = new PopupMenu(this, view);
        getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.edit:
                        popupMenu.dismiss();
                        break;
                    default:
                        Toast.makeText(PopupMenuTest.this,
                                "你单机了" + item.getTitle(), Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });
        popupMenu.show();
    }
}
